var demo = angular.module("demo", ["RongWebIMWidget"]);
demo.controller("main", ["$scope", "WebIMWidget", function($scope,WebIMWidget) {

  $scope.show = function() {
    WebIMWidget.show();
  }

  $scope.hidden = function() {
    WebIMWidget.hidden();
  }

  $scope.server = WebIMWidget;
  $scope.targetType=1;

  $scope.setconversation=function(){
    WebIMWidget.setConversation(Number($scope.targetType), $scope.targetId, "自定义:"+$scope.targetId);
  }

  angular.element(document).ready(function() {

    WebIMWidget.init({
      appkey: "4z3hlwrv3n35t",
      token: "rEBKuGIn7mWeOhI5jWdxCxRaqDNTHyIJps/1HTVvk9szgxto9ack85YzBs93spkF7TAWA1VFLBMp2bkISSyWWg==",
      style:{
        width:500,
        height:600,
        bottom:0,
        right:0,
        positionFixed:true
      },
      displayConversationList:true,
      conversationListPosition:WebIMWidget.EnumConversationListPosition.left,
      displayMinButton:true,
      onSuccess:function(){
          WebIMWidget.setConversation(1, "3argexb6r934e", "新的一天，开开心心！");
      },
      onError:function(error){
        console.log("error:"+error);
      }
    });

    WebIMWidget.setUserInfoProvider(function(targetId,obj){
        obj.onSuccess({name:"客服："+targetId});
    });

    // WebIMWidget.onCloseBefore=function(obj){
    //   console.log("关闭前");
    //   setTimeout(function(){
    //     obj.close();
    //   },1000)
    // }
    WebIMWidget.hdie();

    WebIMWidget.onClose=function(){
      console.log("已关闭");
    }

    // 设置会话
    WebIMWidget.setConversation("KEFU145984144120015 ", "cc", "ABCDEFGHIGKLMNOPQRSTUVWXYZ");

    //接收到消息时
    WebIMWidget.onReceivedMessage = function(message) {
      //message 收到的消息
    }
  });

}]);
